package com.pzj.httpclient;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.DefaultHttpClient;

public class ClientTest {

	/**
	 * @param args
	 * @throws IOException 
	 * @throws ClientProtocolException 
	 */
	public static void main(String[] args) throws ClientProtocolException, IOException {
//		HttpParams params = new BasicHttpParams();
		HttpClient client = new DefaultHttpClient();
		HttpUriRequest request = new HttpPost("http://www.hao123.com");
		HttpResponse response = client.execute(request);
		
		Header[] headers = response.getAllHeaders();
		for(Header header : headers) {
			System.out.println("header name -- >" + header.getName());
			System.out.println("header value -- >" + header.getValue());
		}
		
		HttpEntity entity = response.getEntity();
		InputStream in = entity.getContent();
		BufferedInputStream bin = new BufferedInputStream(in);
		BufferedReader reader = new BufferedReader(new InputStreamReader(bin));
		String line = null;
		while((line = reader.readLine()) != null) {
			System.out.println(new String(line.getBytes(), "gb2312"));
		}
		
	}

}
